﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MsgCenter.Web.Pages.User.Index"
    MasterPageFile="~/Master.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headerContent" runat="server">
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/i18n/grid.locale-cn.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/jquery.jqGrid.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mainContent" runat="server">
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <table id="grid-table">
                </table>
                <div id="grid-pager">
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var gridTableID = 'grid-table';
        var gridPagerID = 'grid-pager';
        var ajaxUrl = "../../Handlers/Handler_User.ashx";
        function ShowConfirm(modelID) {
            var o = {
                DeleteData: { method: "Delete", UserID: modelID, random: Math.random() },
                DeleteURL: ajaxUrl,
                ReLoad: Reload
            };
            showConfirmDialog(o);
        }
        function ShowWindow(varTitle, varUrl) {
            var o = {
                title: varTitle,
                href: varUrl
            };
            showColorbox(o);
        }
        function Add() {
            ShowWindow("用户新增", "Option.aspx?type=Add");
        }

        function Delete() {
            var row = $("#" + gridTableID).jqGrid('getGridParam', 'selarrrow');
            if (row.length > 0) {
                var len = row.length;
                var selectUserID = "";
                for (var i = 0; i < len; i++) {
                    var model = $("#" + gridTableID).jqGrid('getRowData', row[i]);
                    if (model.IsAdmin == "是") {
                        $("#" + gridTableID).setSelection(row[i], false);
                    }
                    else {
                        if (selectUserID == "") {
                            selectUserID = model.UserID;
                        }
                        else {
                            selectUserID += "," + model.UserID;
                        }
                    }
                }
                if (selectUserID == "") {
                    showDialogMessage("请先选择数据或不能删除管理员!");
                }
                else {
                    ShowConfirm(selectUserID);
                }
            }
            else {
                showDialogMessage("请先选择要删除的数据!");
            }
        }

        function Edit() {
            var id = $("#" + gridTableID).getGridParam("selrow");
            if (id) {
                $("#" + gridTableID).resetSelection();
                $("#" + gridTableID).setSelection(id, true);
                var model = $("#" + gridTableID).jqGrid('getRowData', id);
                ShowWindow("用户编辑", "Option.aspx?type=Edit&Guid=" + model.UserID);
            }
            else {
                showDialogMessage("请先选择要修改的数据!");
            }
        }

        function Look() {
            var id = $("#" + gridTableID).getGridParam("selrow");
            if (id) {
                var model = $("#" + gridTableID).jqGrid('getRowData', id);
                ShowWindow("用户查看", "Option_Look.aspx?type=Look&Guid=" + model.UserID);
            }
            else {
                showDialogMessage("请先选择要查看的数据");
            }
        }

        function SetAuth() {
            var id = $("#" + gridTableID).getGridParam("selrow");
            if (id) {
                $("#" + gridTableID).resetSelection();
                $("#" + gridTableID).setSelection(id, true);
                var model = jQuery("#" + gridTableID).jqGrid('getRowData', id);
                ShowWindow("用户权限设置", "Option_Auth.aspx?type=Set&UserID=" + model.UserID);
            }
            else {
                showDialogMessage("请先选择要设置权限的数据!");
            }
        }

        function LookRole(RoleID) {
            if (RoleID) {
                ShowWindow("角色查看", "../Role/Option.aspx?type=Look&Guid=" + RoleID);
            }
            else {
                showDialogMessage("请先选择要查看的数据");
            }
        }

        function cLink(cellvalue, options, rowObject) {
            var aLink = "";
            var szCell = cellvalue.split(',');
            var szCell_ID = rowObject['UserRoleID'].split(',');
            var len = szCell.length;
            var linkText = "";
            for (var i = 0; i < len; i++) {
                if (linkText == "") {
                    linkText = "<a href ='javascript:' onclick=LookRole('" + szCell_ID[i] + "');>" + szCell[i] + "</a>";
                }
                else {
                    linkText += ",<a href ='javascript:' onclick=LookRole('" + szCell_ID[i] + "');>" + szCell[i] + "</a>";
                }
            }
            return linkText;
        }
        jQuery(function ($) {
            var url = ajaxUrl + "?method=GetUserList";
            var colNames = ['UserID', '工号', '用户名称', '所属部门', '手机', '邮箱', 'Rtx登录名', '微信', '出生日期', '登录名', '所属角色', '是否管理员', '是否删除', '创建日期'];
            var colModel = [
				{ name: 'UserID', index: 'UserID', width: 10, editable: false, hidden: true },
				{ name: 'Code', index: 'Code', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'Name', index: 'Name', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'DeptName', index: 'DeptName', width: 20, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'Mobile', index: 'Mobile', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'Email', index: 'Email', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'RtxLoginName', index: 'RtxLoginName', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'WebChat', index: 'WebChat', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
                { name: 'BirthDay', index: 'BirthDay', width: 15, editable: false, formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d' }, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: GridSelectDatePick} },
                { name: 'UserName', index: 'UserName', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
                { name: 'UserRole', index: 'UserRole', search: false, width: 20, editable: false, formatter: cLink, sortable: false },
                { name: 'IsAdmin', index: 'IsAdmin', search: false, width: 10, editable: false,
                    formatter: function (value) {
                        if (value.toString() == "True") {
                            return "是";
                        }
                        else {
                            return "否";
                        }
                    }
                },
                { name: 'IsDelete', index: 'IsDelete', search: false, width: 10, editable: false,
                    formatter: function (value) {
                        if (value.toString() == "True") {
                            return "是";
                        }
                        else {
                            return "否";
                        }
                    }
                },
				{ name: 'CreateDate', index: 'CreateDate', width: 15, editable: false, formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d' }, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: GridSelectDatePick} }
			];
            var dfop =
            {
                GridID: gridTableID,
                GridPagerID: gridPagerID,
                Url: url,
                ColNames: colNames,
                ColModel: colModel,
                Caption: "用户列表",
                SortName: "CreateDate",
                Height: 355,
                OndblClickRow: Look
            };
            showJqGrid(dfop);
            //GetOperateAuth({ Url: "../../Handlers/Handler_UserAuth.ashx?method=GetAuthOperate", GridID: gridTableID, GridPagerID: gridPagerID, ModuleID: "<%=strRequestID %>" });
        });

        function CBClose() {
            $.colorbox.close();
        }

        function CBClose_Load() {
            $.colorbox.close();
            showDialogMessage("操作数据成功");
            Reload();
        }

        function Reload() {
            $("#" + gridTableID).trigger("reloadGrid");
        }
        
    </script>
</asp:Content>
